<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>Hello from Electron renderer!</title>
</head>

<body>
    <h1>Hello from Electron renderer!</h1>
    <p>👋</p>
    <div class="form-row">
        <button onclick="point_list_request()">point_list_request</button>
        <button onclick="tendency_chart_request()">tendency_chart_request</button>
        <button onclick="point_list_v2_request()">point_list_v2_request</button>
        <button onclick="point_save()">point_save</button>
    </div>
    <script>

        function jsonForma(obj) {
            return JSON.stringify(obj, null, 4)
        }

        window.electronAPI.ipcRenderer.on('point_save_response', (result) => {
            console.log("point_save_response result = ", result)
        })

        window.electronAPI.ipcRenderer.on('point_list_response', (result) => {
            console.log("point_list_response result = ", result)
        })

        window.electronAPI.ipcRenderer.on('tendency_chart_response', (result) => {
            console.log("tendency_chart_response result = ", result)
        })

        window.electronAPI.ipcRenderer.on('point_list_v2_response', (result) => {
            console.log("point_list_v2_response result = ", result)
        })

        function point_list_request() {
            console.log("click point_list_request",(new Date()).getTime());
            
            window.electronAPI.ipcRenderer.send('point_list_request', {
                "page": 1,
                "size": 1000,
                "addrs": "55-00-02-000,55-00-02-001",
                "interval": 60,
                "start_time": "2025-06-23 09:23:49",
                "end_time": "2025-06-23 10:23:49"
            })
        }

        function tendency_chart_request() {
            window.electronAPI.ipcRenderer.send('tendency_chart_request', {
                "page": 1,
                "size": 1000,
                "addrs": "55-00-02-000,55-00-02-001",
                "interval": 60,
                "start_time": "2025-06-23 09:23:49",
                "end_time": "2025-06-23 10:23:49"
            })
        }

        function point_list_v2_request() {
            window.electronAPI.ipcRenderer.send('point_list_v2_request', {
                "page": 1,
                "size": 1000,
                "addrs": "55-00-02-000,55-00-02-001",
                "interval": 60,
                "start_time": "2025-06-23 09:23:49",
                "end_time": "2025-06-23 10:23:49"
            })
        }


        let json_data = "[{\"project_id\":1,\"spec_type\":\"float32\",\"addr\":\"55-00-02-000\",\"alert\":\"\",\"alert_type\":null,\"field_name\":\"温度℃\",\"value\":28.642122268676758,\"create_time\":\"2025-06-23 12:03:08\"},{\"project_id\":1,\"spec_type\":\"float32\",\"addr\":\"55-00-02-001\",\"alert\":\"\",\"alert_type\":null,\"field_name\":\"湿度%\",\"value\":37.0863037109375,\"create_time\":\"2025-06-23 12:03:08\"}]"
        function point_save() {
            window.electronAPI.ipcRenderer.send("point_save_request", json_data)
        }
    </script>
</body>

</html>